/**
 * Created by qianjy on 2016/11/29.
 */
require.config(window.jshead);
require(['jquery', 'pages', 'laydate','birthday','navigator'], function ($, pg,laydate,birthday) {
    var birthday = {
        elem: '#birthday',
        format: 'YYYY-MM-DD',
        max: '2099-12-31 23:59:59', //最大日期
        istime: false,
        isclear: false, //是否显示清空,
        issure: false, //是否显示确认
        istoday: false
    };
    $('#birthday').bind("click", function () {
        laydate(birthday);
        $(".laydate_table td").bind("click",function(){
            var beginDateTime=$('#birthday').val();
            var endDateTime=$('#birthday2').val();
            if(beginDateTime && beginDateTime!='' && endDateTime && endDateTime!=''){
                ticketList({beginDateTime:beginDateTime,endDateTime:endDateTime,type:0,operType:null})
            }
        })
    });
    var birthday2 = {
        elem: '#birthday2',
        format: 'YYYY-MM-DD',
        max: '2099-12-31 23:59:59', //最大日期
        istime: false,
        isclear: false, //是否显示清空,
        issure: false, //是否显示确认
        istoday: false
    };
    $('#birthday2').bind("click", function () {
        laydate(birthday2);
        $(".laydate_table td").bind("click",function(){
            var beginDateTime=$('#birthday').val();
            var endDateTime=$('#birthday2').val();
            if(!beginDateTime || beginDateTime==''){
                layer.tips("请选择开始时间",'#birthday');
            }
            if(beginDateTime && beginDateTime!='' && endDateTime && endDateTime!=''){
                ticketList({beginDateTime:beginDateTime,endDateTime:endDateTime,type:0,operType:null})
            }
        })
    });
    var params={type:0,operType:null};
    ticketList(params);
    $('#all').bind('click',function(){
        beginDateTime=$('#birthday').val('');
        endDateTime=$('#birthday2').val('');
        $('#all').addClass('active');
        $('#week').removeClass('active');
        $('#month').removeClass('active');
        $('#season').removeClass('active');
        params.type=0;
        ticketList(params)
    });
    $('#week').bind('click',function(){
        beginDateTime=$('#birthday').val('');
        endDateTime=$('#birthday2').val('');
        $('#all').removeClass('active');
        $('#week').addClass('active');
        $('#month').removeClass('active');
        $('#season').removeClass('active');
        params.type=1;
        ticketList(params)
    });
    $('#month').bind('click',function(){
        beginDateTime=$('#birthday').val('');
        endDateTime=$('#birthday2').val('');
        $('#all').removeClass('active');
        $('#week').removeClass('active');
        $('#month').addClass('active');
        $('#season').removeClass('active');
        params.type=2;
        ticketList(params)
    });
    $('#season').bind('click',function(){
        beginDateTime=$('#birthday').val('');
        endDateTime=$('#birthday2').val('');
        $('#all').removeClass('active');
        $('#week').removeClass('active');
        $('#month').removeClass('active');
        $('#season').addClass('active');
        params.type=3;
        ticketList(params)
    });
    function ticketList(parms){
        pg.paging(1, 14, "/user/account/logList",'moneyList','moneyListTemp',parms,'','');
    }
    $('.day-buts-third').bind('click',function(){
        $(this).addClass("red").siblings().removeClass("red");
    });


    $('.day-buts-third').bind('click',function(){
         beginDateTime=$('#birthday').val('');
         endDateTime=$('#birthday2').val('');
        var aa = $(this).attr('data-type')
        if(aa==0){
            params.operType=null;
            ticketList(params)
        }else if(aa ==1){
            params.operType='invest';
            ticketList(params)

        }else if(aa ==2){
            params.operType="receive_repay";
            ticketList(params)
        }else if(aa==3){
            params.operType="user_recharge_success";
            ticketList(params)
        }else if(aa == 4){

            params.operType="user_cash_success";
            ticketList(params)
        }
    });

    function accountLog(){
        $.ajax({
            type: "POST",
            url: "/account/countAccountLog",
            data: {},
            dataType: "json",
            success: function (data) {
                $("#countAccountLog").html(
                    "<td class='accountLogText'>收入：</td><td class='accountLogText'>"+data.countIncome+"元</td>" +
                    "<td class='accountLogText'>支出：</td><td class='accountLogText'>"+data.countCost+"元</td>")
            }
        });
    };
    accountLog();

});